



public class Solution {
    public String longestPalindrome(String s) {
        boolean[][] dp=new boolean[s.length()][s.length()];
        int right=0;
        int left=0;
        int maxLength=0;
        char[] chars = s.toCharArray();
        for(int i=s.length();i>=0;i--){
            for(int j=i;j<s.length();j++){
                if(chars[i]==chars[j]){
                    if(j-i<=1){
                        dp[i][j]=true;
                    }else  if(dp[i+1][j-1]){
                        dp[i][j]=true;
                    }
                }
                if(dp[i][j]&&j-i+1>maxLength){
                    maxLength=j-i+1;
                    left=i;
                    right=j;
                }

            }
        }
        return s.substring(left,right+1);
    }
}
